// 类型别名
// 类型别名用来给一个类型起个新名字。


// 类型名别名
type S = string;
type N = number;
type B = boolean;
type List = number[];
type SN = string | number;
type Data = {   // 类似 interface
    name: string,
    age?: number,
    [propName: string]: any
}


var str: S = "100";
var num: N = 100;
var abc: SN = 100;

var tom: Data = {
    name: "Tom",
}

type Name = string;
type NameResolver = () => string;
type Params = Name | NameResolver;
function getName(n: Params): Name {
    if (typeof n === 'string') {
        return n;
    } else {
        return n();
    }
}



// 字符串字面量类型 => 别名
// type Type = "get" | "post" | "put" | "delete";


// function ajax(type: Type, url: S, data: string | object) {

// }
// ajax("put", "/login", { a: 1 })

type eventType = "click" | "dblclick" | "mousedown";
type callback = () => any;

function bindEvent(ele: Element, eventType: eventType, fn: callback): void {
    ele.addEventListener(eventType, fn);
}






export default 100;